/**
 * @Title: SpiderExceptionInfoContorller.java
 * @Package cn.com.klun.tjy.controller
 * @Description: TBL_SPIDER_EXCEPTION_INFO的控制器
 * @author GOME
 * @date Sun Feb 11 15:55:19 CST 2018
 * @company cn.com.gome
 * @version V1.0
 */

package cn.com.klun.tjy.admin.controller;

import cn.com.klun.tjy.admin.common.AbstractAdminController;
import cn.com.klun.tjy.admin.common.EntityPersistenceLayerService;
import cn.com.klun.tjy.common.baseInterface.PersistenceLayerSerMapper;
import cn.com.klun.tjy.common.basePojo.PageQueryEntitys;
import org.apache.commons.lang.StringUtils;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Arrays;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONArray;
import org.springframework.ui.Model;
import java.util.List;
import cn.com.klun.tjy.dao.entity.TblSpiderExceptionInfo;
import cn.com.klun.tjy.vo.SpiderExceptionInfoVo;
import cn.com.klun.tjy.dao.mapper.edit.TblSpiderExceptionInfoEditMapper;
import cn.com.klun.tjy.dao.mapper.ser.TblSpiderExceptionInfoSerMapper;

/**
 * @ClassName: SpiderExceptionInfoContorller
 * @Description: TBL_SPIDER_EXCEPTION_INFO的控制器
 * @author GOME
 * @date 2015年2月10日 下午2:35:34
 */
@Controller
@RequestMapping("/spiderexceptioninfo")
public class SpiderExceptionInfoController extends AbstractAdminController {

	@Autowired
	private EntityPersistenceLayerService entityPersistenceLayerService;

	@Autowired
	private TblSpiderExceptionInfoEditMapper tblSpiderExceptionInfoEditMapper;

	@Autowired
	private TblSpiderExceptionInfoSerMapper tblSpiderExceptionInfoSerMapper;

	@RequestMapping("/inits")
	public String init(Model model,HttpServletRequest request, HttpServletResponse response) {

		return "spiderexceptioninfo/inits";
	}

	@RequestMapping("/search")
	public void search(@ModelAttribute("pageQueryEntitys") PageQueryEntitys pageQueryEntitys, HttpServletRequest request, HttpServletResponse response) {
		try {
			pageQueryEntitys.setEntityClassName("TblSpiderExceptionInfo");
			String stockCode = request.getParameter("stockCode");
			if (StringUtils.isNotEmpty(stockCode)) {
				pageQueryEntitys.addF("stockCode", stockCode);
			}
			String ex = request.getParameter("ex");
			if (StringUtils.isNotEmpty(ex)) {
				pageQueryEntitys.addF("ex", ex);
			}
			String date = request.getParameter("date");
			if (StringUtils.isNotEmpty(date)) {
				pageQueryEntitys.addF("date", date);
			}
			String lockFlag = request.getParameter("lockFlag");
			if (StringUtils.isNotEmpty(lockFlag)) {
				pageQueryEntitys.addF("lockFlag", lockFlag);
			}
			String lockCounts = request.getParameter("lockCounts");
			if (StringUtils.isNotEmpty(lockCounts)) {
				pageQueryEntitys.addF("lockCounts", lockCounts);
			}
			String creTime = request.getParameter("creTime");
			if (StringUtils.isNotEmpty(creTime)) {
				pageQueryEntitys.addF("creTime", creTime);
			}
			pageQueryEntitys = entityPersistenceLayerService.queryPageVoList((PersistenceLayerSerMapper) tblSpiderExceptionInfoSerMapper, pageQueryEntitys);
		} catch (Exception e) {
			logger.error(" TBL_SPIDER_EXCEPTION_INFO的控制器执行异常【search】",e);
		}
		ajaxJsonPage(JSONArray.fromObject(pageQueryEntitys.getList()).toString(),pageQueryEntitys.getTotalCount(),response);
	}

	@RequestMapping("/select")
	public void select(HttpServletRequest request, HttpServletResponse response) {
		try {
			TblSpiderExceptionInfo obj = new TblSpiderExceptionInfo();
			List<TblSpiderExceptionInfo> list = tblSpiderExceptionInfoSerMapper.queryList(obj);
			ajaxJsonMessage(response,JSONArray.fromObject(list).toString());
		} catch (Exception e) {
			logger.error(" TBL_SPIDER_EXCEPTION_INFO的控制器执行异常【select】",e);
		}
	}

	@RequestMapping("/add")
	public String add(HttpServletRequest request, HttpServletResponse response,Model model){
		model.addAttribute("resultType", "add");
		return "spiderexceptioninfo/add";
	}

	@RequestMapping("/save")
	public String save(@ModelAttribute("enitty") TblSpiderExceptionInfo enitty,HttpServletRequest request, HttpServletResponse response,Model model) {
		try {
			model.addAttribute("resultStatus", "false");
			enitty.setTaskUpdateTime(new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()));
			tblSpiderExceptionInfoEditMapper.save(enitty);
			model.addAttribute("messages", "温馨提示：添加成功！");
			model.addAttribute("resultStatus", "true");
		} catch (Exception e) {
			model.addAttribute("messages", "温馨提示：添加异常:" + e.getMessage());
			logger.error(" spiderexceptioninfo的控制器执行异常【save】",e);
		}
		model.addAttribute("ADN_ADD_URL", "spiderexceptioninfo/add.dhtml");
		return "success";

	}

	@RequestMapping("/query")
	public String query(HttpServletRequest request, HttpServletResponse response,Model model) {
		try {
			model.addAttribute("resultType", "edit");
			model.addAttribute("resultStatus", "false");
			TblSpiderExceptionInfo enitty = new TblSpiderExceptionInfo();
			enitty.setId(Integer.valueOf(request.getParameter("id_key")));
			enitty = (TblSpiderExceptionInfo) tblSpiderExceptionInfoSerMapper.queryObj(enitty);
			if (enitty != null){
				model.addAttribute("enitty", enitty);
				model.addAttribute("resultStatus", "true");
				return "spiderexceptioninfo/add";
			}
			model.addAttribute("messages", "温馨提示：没有查询到符合条件的记录！");

		} catch (Exception e) {
			model.addAttribute("messages", "温馨提示：查询异常:" + e.getMessage());
			logger.error(" spiderexceptioninfo的控制器执行异常【query】",e);
		}
		return "success";
	}

	@RequestMapping("/edit")
	public String edit(@ModelAttribute("enitty") TblSpiderExceptionInfo enitty,HttpServletRequest request, HttpServletResponse response,Model model) {
		try {
			model.addAttribute("resultStatus", "false");
			enitty.setTaskUpdateTime(new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()));
			int count = tblSpiderExceptionInfoEditMapper.edit(enitty);
			if (count == 0) {
				model.addAttribute("messages", "温馨提示：修改失败！");
			} else {
				model.addAttribute("messages", "温馨提示：修改成功！");
				model.addAttribute("resultStatus", "true");
				TblSpiderExceptionInfo enittyNew = new TblSpiderExceptionInfo();
				enittyNew.setId(enitty.getId());
				enittyNew = (TblSpiderExceptionInfo) tblSpiderExceptionInfoSerMapper.queryObj(enittyNew);
				model.addAttribute("enitty", enittyNew);
				model.addAttribute("resultStatus", "true");
				model.addAttribute("resultType", "edit");
				return "spiderexceptioninfo/add";
			}
		} catch (Exception e) {
			model.addAttribute("messages", "温馨提示：修改异常:" + e.getMessage());
			logger.error(" spiderexceptioninfo的控制器执行异常【edit】",e);
		}
		return "success";
	}

	@RequestMapping("/del")
	public void del(HttpServletRequest request, HttpServletResponse response,Model model) {
		try {
			model.addAttribute("resultStatus", "false");
			int count = tblSpiderExceptionInfoEditMapper.del(Arrays.asList(request.getParameter("id_key").split(",")));
			if (count == 0) {
				ajaxJsonMessage(response,"0002","温馨提示：没有删除到符合条件的记录！","");
			} else {
				ajaxJsonMessage(response,"0000","温馨提示：删除成功！","");
			}
		} catch (Exception e) {
			ajaxJsonMessage(response,"0002","温馨提示：删除失败！","");
			logger.error(" spiderexceptioninfo的控制器执行异常【del】",e);
		}
	}

	@RequestMapping("/view")
	public String view(HttpServletRequest request, HttpServletResponse response,Model model) {
		try {
			model.addAttribute("resultType", "view");
			model.addAttribute("resultStatus", "false");
			TblSpiderExceptionInfo enitty = new TblSpiderExceptionInfo();
			enitty.setId(Integer.valueOf(request.getParameter("id_key")));
			SpiderExceptionInfoVo vo = (SpiderExceptionInfoVo) tblSpiderExceptionInfoSerMapper.queryVo(enitty);
			if (vo != null){
				model.addAttribute("enitty", vo);
				model.addAttribute("resultStatus", "true");
			}else{
				model.addAttribute("messages", "温馨提示：没有查询到符合条件的记录！");
			}
		} catch (Exception e) {
			model.addAttribute("messages", "温馨提示：查询异常:" + e.getMessage());
			logger.error(" spiderexceptioninfo的控制器执行异常【view】",e);
		}
		return "spiderexceptioninfo/add";
	}

}
